package cn.tedu.circle.admin.account.controller;

import cn.tedu.circle.admin.account.pojo.entity.User;
import cn.tedu.circle.admin.account.pojo.param.UserUpdateInfoParam;
import cn.tedu.circle.admin.account.pojo.vo.UserListItemVO;
import cn.tedu.circle.admin.account.service.IUserService;
import cn.tedu.circle.common.pojo.vo.PageData;
import cn.tedu.circle.common.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@Api(tags = "账户管理")
@RestController
@RequestMapping("/admin/account")
public class UserController {
    @Autowired
    IUserService iUserService;

    @PostMapping("list")
    @ApiOperation(value = "查询角色列表添加分页")
    public JsonResult list(Integer pageNum,Integer pageSize) {

        PageData<UserListItemVO> list = iUserService.list(pageNum, pageSize);
        return JsonResult.ok(list);
    }

    @PostMapping("/delete")
    @ApiOperation(value = "删除角色")
    public JsonResult delete(@RequestParam(value = "id") Long id) {
        iUserService.deleteById(id);
        return JsonResult.ok();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改角色信息")
    public JsonResult update(UserUpdateInfoParam userUpdateInfoParam) {
        iUserService.updateById(userUpdateInfoParam);
        return JsonResult.ok();
    }

    @PostMapping("/update/role")
    @ApiOperation(value = "更改用户角色")
    public JsonResult updateRole(Long id,Integer roleId) {
        iUserService.updateRole(id,roleId);
        return JsonResult.ok();
    }


    @PostMapping("/update/enable")
    @ApiOperation(value = "禁用角色")
    public JsonResult updateEnable(Long id,Integer enable) {
        iUserService.updateEnable(id,enable);
        return JsonResult.ok();
    }

}
